package com.concurrence;

/**
 * InterruptAQS..    // Interrupt 不能中断Running,没有阻塞、等待 只会修改中断标志位，并不会抛出中断异常，程序正常执行
 *
 * @author Lizhong
 * @date 2019/4/3
 */
public class InterruptAQS {
    public static void main(String[] args) throws InterruptedException {

        Thread thread = new Thread(new Runner());
        thread.start();

        Thread.sleep(1000);

        System.out.println("start interrupt thread!");
        // 并没有抛出中断异常
        thread.interrupt();

        thread.join();
        System.out.println("end");

    }

    static class Runner implements Runnable {
        @Override
        public void run() {
            try {
                Thread.currentThread().setName("test");
                System.out.println("thread-start");
                for (int i = 0; i < 10; i++) {
                    for (int j = 0; j < 10000000; j++) {
                        Math.sin(0.34334);
                    }
                    System.out.println("i="+i);
                }
                System.out.println("thread-end");
            } catch (Exception e) {
                System.out.println("catch");
            } finally {
                System.out.printf("finally~~,interrupted={%s}", Thread.interrupted());
            }
        }
    }
}